package com.dr.springboot.starter;

import com.dr.springboot.starter.config.interceptor.InterceptorConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

//todo interceptor 需要继承WebMvcConfigurerAdapter类来进行配置，想要配置生效需要加上@Configuration
@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter  {

    @Autowired
    private InterceptorConfig interceptorConfig;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自定义拦截器，添加拦截路径和排除拦截路径
        registry.addInterceptor(interceptorConfig)
//                todo interceptor 这里的路径只包括controller上配置的，不含web容器的路径
                .addPathPatterns("/interceptor/**");
        super.addInterceptors(registry);
    }

}